package com.lovo.roomProject.room.dao.impl;

import com.lovo.roomProject.dao.BaseDAO;
import com.lovo.roomProject.pojo.RoomDO;
import com.lovo.roomProject.room.dao.RoomDAO;

import java.sql.SQLException;
import java.util.ArrayList;
import java.util.List;

public class RoomDAOImpl extends BaseDAO implements RoomDAO {
    @Override
    public List listRoom() {
        this.getConnection();
        String sql1 = "SELECT r_addr,r_count,r_status,count(s_r_id) as 已住人数,r_type from t_student s left join t_room r on s.s_r_id=r.r_id GROUP BY r_addr";
        List list = new ArrayList();
        try {
            preparedStatement = con.prepareStatement(sql1);
            rs = preparedStatement.executeQuery();
            while (rs.next()) {
                RoomDO room = new RoomDO();
                room.setAddr(rs.getString("r_addr"));
                room.setCount(rs.getInt("r_count"));
                room.setStatus(rs.getString("r_status"));
                room.setType(rs.getString("r_type"));
                room.setInCount(rs.getInt("已住人数"));
                list.add(room);
            }
        } catch (SQLException throwables) {
            throwables.printStackTrace();
        }finally {
            close(con,preparedStatement,rs);
        }
        return list;
    }
}
